﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BPM.Foundation.WFDB;
using BPM.ClientLink.wfs;

namespace BPM.Base.WFLib.GuideForm
{
    public partial class WFBrowseForm : System.Windows.Forms.Form
    {
        public WFBrowseForm()
        {
            InitializeComponent();

        }


        private void FillTemplate()
        {
            try
            {
                this.lbTemplate.DisplayMember = "templateId";
                this.lbTemplate.DataSource = wfs.getWFS().searchWFTemplate("", tbTemplateId.Text, tbTemplateEdtion.Text);

            }
            catch (Exception myEx)
            {
                MessageBox.Show(myEx.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void lbTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {
            WF_Template_V wfv = this.lbTemplate.SelectedItem as WF_Template_V;
            if (wfv != null)
            {

                FillWFTemplate(wfv);
            }

        }

        private void FillWFTemplate(WF_Template_V wfv)
        {

            WF_Structure wfStruct;
            if (wfv != null)
            {
                wfStruct = wfs.getWFS().getWFStructure("", wfv.templateID, wfv.templateEdition);

                var TemplateVCN = new
                {

                    模板编号 = wfStruct.wfTemplateV.templateID,
                    模板版本 = wfStruct.wfTemplateV.templateEdition,
                    模板名称 = wfStruct.wfTemplateV.templateName,
                    模板说明 = wfStruct.wfTemplateV.templateDescription,
                    模板类型 = wfStruct.wfTemplateV.templateType,
                    业务类型 = wfStruct.wfTemplateV.businessType,
                    模板状态 = wfStruct.wfTemplateV.templateState,
                    签出时间 = wfStruct.wfTemplateV.outTime,
                    签入时间 = wfStruct.wfTemplateV.inTime,
                    签出部门 = wfStruct.wfTemplateV.outDepartment,
                    签出人员 = wfStruct.wfTemplateV.outUser,
                    创建时间 = wfStruct.wfTemplateV.createTime,
                    创建部门 = wfStruct.wfTemplateV.createDepartment,
                    创建人员 = wfStruct.wfTemplateV.createUser
                };

                pgTemplateV.SelectedObject = TemplateVCN;
                var TemplateInfoCN = new
                {

                    模板编号 = wfStruct.wfTemplateInfo.templateID,
                    模板版本 = wfStruct.wfTemplateInfo.templateEdition,
                    模板名称 = wfStruct.wfTemplateInfo.templateName,
                    模板说明 = wfStruct.wfTemplateInfo.templateDescription,
                    扩展数据 = wfStruct.wfTemplateInfo.expandData,
                    模板类型 = wfStruct.wfTemplateInfo.templateType,
                    启动窗体 = wfStruct.wfTemplateInfo.startWindow,
                    数据表单列表 = wfStruct.wfTemplateInfo.dataFormList,
                    启动时填写的表单 = wfStruct.wfTemplateInfo.startDataForm,
                    管理部门 = wfStruct.wfTemplateInfo.manageDepartment,
                    管理职能 = wfStruct.wfTemplateInfo.manageDuty,
                    管理人员 = wfStruct.wfTemplateInfo.manageUser,
                    查看部门 = wfStruct.wfTemplateInfo.seeDepartment,
                    查看职能 = wfStruct.wfTemplateInfo.seeDuty,
                    查看人员 = wfStruct.wfTemplateInfo.seeUser,
                    启动人员特殊权限 = wfStruct.wfTemplateInfo.startUserPower,
                    办理时限 = wfStruct.wfTemplateInfo.transactTimelimit,
                    超时操作 = wfStruct.wfTemplateInfo.overtimeOperate,
                    权限编号 = wfStruct.wfTemplateInfo.powerID

                };

                pgTemplateInfo.SelectedObject = TemplateInfoCN;

                lbStateInfo.DataSource = wfStruct.wfTemplateStateInfo;
                lbStateInfo.DisplayMember = "stateName";

            }

        }

        private void lbStateInfo_SelectedIndexChanged(object sender, EventArgs e)
        {

            WF_TemplateStateInfo wfStateInfo = this.lbStateInfo.SelectedItem as WF_TemplateStateInfo;
            FillWFState(wfStateInfo);
        }

        private void FillWFState(WF_TemplateStateInfo wfState)
        {
            if (wfState != null)
            {
                var TemplateStateInfoCN = new
                {
                    ID = wfState,
                    权限编号 = wfState.powerID,
                    模板编号 = wfState.templateID,
                    模板版本 = wfState.templateEdition,
                    状态编号 = wfState.stateID,
                    状态名称 = wfState.stateName,
                    状态说明 = wfState.stateDescription,
                    处理方式 = wfState.transactType,
                    扩展数据 = wfState.expandData,
                    启动窗体 = wfState.startWindow,
                    数据表单类型 = wfState.dataFormType,
                    数据分流表达式 = wfState.dataExpression,
                    办理人员 = wfState.transactUser,
                    办理时特殊权限 = wfState.transactPower,
                    办理时限 = wfState.transactTimelimit,
                    办理超时操作 = wfState.transactOvertimeOperate,
                    办理提交选项 = wfState.transactOption,
                    办理查看业务表单 = wfState.transactSeeForm,
                    办理添写业务表单 = wfState.transactWriteForm,
                    接件部门 = wfState.inceptDepartment,
                    接件职能 = wfState.inceptDuty,
                    接件时特殊权限 = wfState.inceptPower,
                    接件时限 = wfState.inceptTimelimit,
                    接件超时操作 = wfState.inceptOvertimeOperate,
                    分配部门 = wfState.assignDepartment,
                    分配职能 = wfState.assignDuty,
                    分配人员 = wfState.assignUser,
                    分配时特殊权限 = wfState.assignPower,
                    分配时限 = wfState.assignTimelimit,
                    分配超时操作 = wfState.assignOvertimeOperate,
                    管理部门 = wfState.manageDepartment,
                    管理职能 = wfState.manageDuty,
                    管理人员 = wfState.manageUser,
                    管理时特殊权限 = wfState.managePower,
                    查看部门 = wfState.seeDepartment,
                    查看职能 = wfState.seeDuty,
                    查看人员 = wfState.seeUser,
                    查看时特殊权限 = wfState.seePower,
                    动态域部门 = wfState.dynamicDepartment,
                    动态域职能 = wfState.dynamicDuty,
                    动态域人员 = wfState.dynamicUser,
                    动态域特殊权限 = wfState.dynamicPower,
                    动态域时限 = wfState.dynamicTimelimit,
                    动态域类型 = wfState.dynamicType
                };
                this.pgStateInfo.SelectedObject = TemplateStateInfoCN;

            }
        }

        private void frmWFBrowse_Load(object sender, EventArgs e)
        {
            this.FillTemplate();
        }
        public string fileName = "";
        public string edition = "";
      


        private void toolStripButton1_Click(object sender, EventArgs e)
        {

            this.FillTemplate();

        }



        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            WF_TemplateStateInfo wfStateInfo = this.lbStateInfo.SelectedItem as WF_TemplateStateInfo;
            if (wfStateInfo != null)
            {

                fileName = wfStateInfo.templateID;
                edition =wfStateInfo.templateEdition;
              
                this.Hide();
            }
        }



    }
}
